package com.wzp.yyptproject.controller;


import com.wzp.yyptproject.entity.Doctor;
import com.wzp.yyptproject.entity.User;
import com.wzp.yyptproject.entity.YuYue;
import com.wzp.yyptproject.entity.YuYue2;
import com.wzp.yyptproject.repository.DoctorRepository;
import com.wzp.yyptproject.repository.YuYueRepository;
import com.wzp.yyptproject.service.DoctorService;
import com.wzp.yyptproject.service.UserService;
import com.wzp.yyptproject.service.YuYueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("yuyue")
public class YuYueController {
    @Autowired
    private YuYueService yuYueService;
    @Autowired
    private YuYueRepository yuYueRepository;

    @PostMapping("findyuyue")
    public List<YuYue2> findAndByUid(@RequestBody User user){
        List<YuYue>  yuYueList= yuYueService.findAndByUid(user.getUname(),user.getUidcard());
        List<YuYue2> yuYue2List =yuYueService.findAllyuyue(yuYueList);
            return yuYue2List;

    }

    @PostMapping("addyuyue")
    public String addYuYue(@RequestBody YuYue2 yuYue2) {
        System.out.println(yuYue2.getOdates());
        System.out.println(yuYue2.getOtimes());
        if (yuYueService.addYuYue(yuYue2.getUname(), yuYue2.getUidcard(),
                yuYue2.getDid(), yuYue2.getOdates(), yuYue2.getOtimes()) == "success") {
            yuYueService.getChickCode();
            return "success";
        }
        if (yuYueService.addYuYue(yuYue2.getUname(), yuYue2.getUidcard(),
                yuYue2.getDid(), yuYue2.getOdates(), yuYue2.getOtimes()) == "failed1"){
            System.out.println("failed1");
            return "failed1";
    }     if (yuYueService.addYuYue(yuYue2.getUname(), yuYue2.getUidcard(),
                yuYue2.getDid(), yuYue2.getOdates(), yuYue2.getOtimes()) == "failed2"){
            System.out.println("failed2");
            return "failed2";
        }
        return "failed";
    }

    @GetMapping("deleteyuyue")
    public String deleteYuYue( Integer oid ){
        if (yuYueService.deleteYuYue(oid)==true){

            return "success";
        }

       return "failed";
  }


}



